// pages/ProjectDetails/ProjectDetails.js
const axios = require('../../utils/http.js');
const app = getApp()
Page({

  onShareAppMessage: function(res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '自定义转发标题',
      path: '/pages/Reward/Reward'
    }
  },

  /**
   * 页面的初始数据
   */
  data: {
    switchcolor: app.data.switchcolor,
    project: {
      pro_id: 0,
      user_id: 0,
      pro_name: "",
      pro_desc: "",
      pro_imgs: [],
      deadline: "",
      number:0,
      user_id:0,
      pre_reward: 0,
      real_reward: 0,
      pro_status: 0,
      share_count: "0",
      read_count: "0",
      attention_count: 0,
      meshapenum: 100,
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.data.project.pro_id = options.id;
  },

  /**
   * 项目详情
   */
  projectDetailsHttp: function(proId) {
    var that = this;
    var parame = {
      pro_id: proId,
      user_id:100
    }
    axios.POST(true, 'Orders/order_detail', parame, function(res) {
      var images = res.pro_imgs.split(',');
      var projectMessage = res;
      console.log(images.length)
      projectMessage.pro_imgs = images
      that.setData({
        project: projectMessage
      })
    });
  },


  /**
   * 图片点击详情
   */
  previewImage: function(e) {
    var current = e.target.dataset.src;
    wx.previewImage({
      current: current, // 当前显示图片的http链接
      urls: this.data.project.pro_imgs // 需要预览的图片http链接列表
    })
  },

  shapeclick: function() {
    wx.navigateTo({
      url: '../Transmit3/Transmit3?proId=' + this.data.project.pro_id + '&userId=' + this.data.project.user_id
    })
  },

  editProjectClick: function(v) {
    var pId = v.currentTarget.dataset.pro_id;
    wx.navigateTo({
      url: '../EditProject/EditProject?pId=' + pId,
    })
  },

  rewardclick: function() {
    wx.navigateTo({
      url: '../Reward/Reward?proId=' + this.data.project.pro_id + "&money=" + this.data.project.pre_reward
    })
  },

  rewarddetailsclick: function(e) {
    wx.navigateTo({
      url: '../RewardDetails/RewardDetails?proId=' + this.data.project.pro_id
    })
  },

  isForwardclick: function(e) {
    var that = this;
    var projectnew = this.data.project;
    var falg = e.currentTarget.dataset.flag;

    var parame = {
      pro_id: projectnew.pro_id,
      pro_status: falg
    }
    axios.POST(true, 'Orders/order_status', parame, function(res) {
      projectnew.pro_status = parame.pro_status;
      that.setData({
        project: projectnew
      })
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.projectDetailsHttp(this.data.project.pro_id)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },

  showModal: function(v) {
    var that = this;
    axios.model("删除项目", "确定删除该项目吗？", true, "确定", "#ff0000", function(res) {
      if (true == res) {
        that.deleteProjectHttp(v.currentTarget.dataset.pro_id)
      }
      // axios.ti("成功", "success");
      // wx.navigateBack({})
    })
  },

  deleteProjectHttp: function(pro_id) {
    var parame = {
      pro_id: pro_id
    }
    console.log(parame);
    // axios.ti("成功", "success");
    axios.POST(true, '/Orders/order_delete', parame, function(res) {
      axios.ti("成功", "success");
        wx.navigateBack({

      })
    });
  }
})